package com.zyp.boot01.controller;

import com.zyp.boot01.entity.Emp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController // 添加此注解后就不用在每个方法上面添加@ResponseBody注解了
public class ParamController {
    @RequestMapping("/p1")
    //@ResponseBody // 通过返回值的方式给客户端响应数据
    public String p1(HttpServletRequest request){
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return "测试1成功！<br> name="+name+" <br> age="+age+"";
    }

    @RequestMapping("/p2")
    //@ResponseBody
    public String p2(String name,int age){
        return "测试2成功！<br> name="+name+" <br> age="+age+"";
    }

    @RequestMapping("/p3")
    //@ResponseBody
    public String p3(Emp emp){// SpringMVC框架通过反射技术 将接受到的参数直接封装到对象里面
        // soutp
        System.out.println("emp = " + emp + "");
        return emp.toString();
    }
}
